<?php
/**
 * @version		$Id: controller.php 
 * @package		Clickdesk
 * @subpackage	Clickdesk
 * @license		GNU/GPL, see LICENSE.php
 * Joomla! is free software. This version may have been modified pursuant to the
 * GNU General Public License, and as distributed it includes or is derivative
 * of works licensed under the GNU General Public License or other free or open
 * source software licenses. See COPYRIGHT.php for copyright notices and
 * details.
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );

jimport( 'joomla.application.component.controller' );

/**
 * @package		Joomla
 * @subpackage	Config
 */
class ClickdeskController extends JController
{
	/**
	 * Custom Constructor
	 */
	function __construct( $default = array())
	{
		parent::__construct( $default );
	}

	function display( )
	{
 

		//Set the default view, just in case
		$view = JRequest::getCmd('view');
		if(empty($view)) {
			JRequest::setVar('view', 'clickdesk');
		};


		$db	=& JFactory::getDBO(); 
 






		$saveclickdesk =  $_REQUEST['savecheckdesk'];
		$widgetid =   $_REQUEST['widgetid'];
		$checkclickid =  $_REQUEST['checkclickid'];

		$cdwidgetid =  $_REQUEST['cdwidgetid'];

		if($cdwidgetid != "")
		{
				$sql ="delete from #__clickdesk";
				$db->setQuery($sql );
				$db->query(); 			


				$sql ="insert into #__clickdesk values('','".$cdwidgetid."')";
				$db->setQuery($sql );
				$db->query(); 				

		}

		if($saveclickdesk == "Save")
		{

			if($checkclickid == 0)
			{
 
				$sql ="insert into #__clickdesk values('','".$widgetid."')";
				$db->setQuery($sql );
				$db->query(); 

 
			}else
			{
				$sql ="update #__clickdesk set widget_id ='".$widgetid."' where id='".$checkclickid."' ";
				$db->setQuery($sql );
				$db->query(); 
			}
		}


		parent::display();
	}
 

 
}